﻿@using NewLife;
@using XCode;
@using XCode.Configuration;
@{
    var pair = Model as Pair;
    var entity = pair.First as IEntity;
    var item = pair.Second as FieldItem;

    var err = 0;
    ModelState st = null;
    if (ViewData.ModelState.TryGetValue(item.Name, out st) && st != null) { err = st.Errors.Count; }

    var des = item.Description.TrimStart(item.DisplayName).TrimStart(",", ".", "，", "。");

    var total = 12;
    var label = 3;
    var span = 4;
    if (err == 0 && des.IsNullOrEmpty())
    {
        span = 0;
    }
    else if (item.Type == typeof(Boolean) || item.Type.IsEnum)
    {
        span += 1;
    }
    //else if (item.Type == typeof(DateTime))
    //{
    //    span += 1;
    //    total--;
    //}
    var input = total - label - span;
}
<label class="control-label col-xs-@label col-sm-@label">@item.DisplayName</label>
<div class="input-group col-xs-@(total - label) col-sm-@input">
    @Html.ForEditor(item, entity)
</div>
@if (err > 0)
{
    <span class="col-sm-@span alert alert-danger">
        @Html.ValidationMessage(item.Name)
    </span>
}
else if (!des.IsNullOrEmpty())
{
    <span class="hidden-xs col-sm-@span">@Html.ForDescription(item)</span>
}
